import React from "react";
import avatar from '../images/avatar.png'; // 导入图片

class From extends React.Component {
  txtRef = React.createRef()
  state = {
    // 发表评论数据
    txt: ''
  }
  handeelTxt = (e) => {
    this.setState({
      txt: e.target.value
    })
  }
  change = () => {
    this.props.handelChange(this.state.txt)
    this.setState({
      txt: ''
    })
    this.txtRef.current.focus()
  }
  render() {
    return (
      <div className="comment-send-container">
        <div>
          <img className="user-head" src={avatar} alt="头像" />
        </div>
        <div className="comment-send">
          <div className="textarea-container">
            <textarea
              ref={this.txtRef}
              cols="80"
              rows="5"
              value={this.state.txt}
              onChange={(e) => this.handeelTxt(e)}
              placeholder="发条友善的评论"
              className="ipt-txt"
            />
            <button className="comment-submit" onClick={() => { this.change() }}>发表评论</button>
          </div>
          <div className="comment-emoji">
            <i className="face"></i>
            <span className="text">表情</span>
          </div>
        </div>
      </div>
    )
  }
}
export default From